<template>
	<view class="study-detail">
		<view v-if="!showLoading">
			<u-swiper :list="info.merchInfo.visualsList" height="400rpx" @change="change" @click="click"></u-swiper>
			<view class="info">
				<view class="title">
					{{info.merchInfo.name}}
				</view>
				<view class="info-item">
					周边类型：{{info.merchInfo.typeName}}
				</view>
				<view class="info-item">
					出品单位：{{info.merchInfo.producer}}
				</view>
			</view>
			<view class="intro">
				<view class="intro-title">
					周边简介
				</view>
				<view class="intro-content">
					{{info.merchInfo.intro || '无'}}
				</view>
			</view>
		</view>
		<view v-else>
			<u-skeleton rows="0" titleWidth="100%" titleHeight="200"></u-skeleton>
			<view class="info">
				<u-skeleton rows="2" titleWidth="40%" rowsWidth="50%"></u-skeleton>
			</view>
			<view class="intro">
				<view class="intro-title">
					周边简介
				</view>
				<u-skeleton rows="3" titleWidth="100%" rowsWidth="100%"></u-skeleton>
			</view>
		</view>
		<view class="event" v-if="info.merchInfo.eventList.length > 0">
			<view class="event-title">
				周边相关研学
			</view>
			<view class="event-list">
				<view class="event-list-item" v-for="(item, index) in info.merchInfo.eventList" @click="toEventDetail(item.id)">
					<view class="event-list-item-title">
						{{item.name}}
					</view>
					<view class="event-list-item-subtitle">
						研学时间：{{item.time}}
					</view>
					<view class="event-list-item-subtitle">
						研学地址：{{item.address}}
					</view>
				</view>
			</view>
		</view>
		<view class="footer" v-if="!showLoading">
			<view class="btn" @click="tobuy(info.merchInfo.buyUrl)">
				去购买
			</view>
		</view>
		<web-view v-if="showWebView" :webview-styles="webviewStyles" src="https://uniapp.dcloud.io/static/web-view.html"></web-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				showLoading: true,
				info: {},
				showWebView: false,
				webviewStyles: {
					progress: {
						color: '#FF3333'
					}
				}
			}
		},
		onLoad(options) {
			this.id = options.id;
			this.getInfo(this.id);
		},
		onPullDownRefresh() {
			this.getInfo(this.id);
			uni.stopPullDownRefresh();
		},
		methods: {
			async getInfo(id) {
				const res = await this.$api('/study/mobile/merch/info', 'get', {
					id
				});
				this.showLoading = false;
				this.info = res.data;
			},

			toEventDetail(id) {
				uni.navigateTo({
					url: `/pages/study/detail?id=${id}`
				})
			},
			
			tobuy(buyUrl) {
				uni.navigateTo({
					url: `/pages/study/tobuy?buyUrl=${buyUrl}`
				})
				// this.showWebView = true;
			},
		}
	}
</script>

<style lang="scss" scoped>
	.study-detail {
		padding-bottom: 150rpx;

		.info {
			margin: 20rpx;
			padding: 20rpx;
			background-color: #fff;
			border-radius: 20rpx;

			.title {
				padding-bottom: 20rpx;
				border-bottom: 1rpx solid #ddd;
				font-size: 32rpx;
				color: #218BCC;
			}

			.info-item {
				padding-top: 20rpx;
				font-size: 28rpx;
				color: #666;
			}
		}

		.intro {
			margin: 20rpx;
			padding: 20rpx;
			background-color: #fff;
			border-radius: 20rpx;

			.intro-title {
				padding: 20rpx 0;
				border-bottom: 1rpx solid #ddd;
				font-size: 32rpx;
				color: #74BB2A;
			}

			.intro-content {
				padding-top: 20rpx;
				font-size: 28rpx;
				color: #999;
			}
		}

		.event {
			margin: 40rpx 20rpx;

			&-title {
				padding-left: 20rpx;
				font-size: 32rpx;
				color: #74BB2A;
			}

			&-list {
				&-item {
					background-color: #fff;
					margin-top: 20rpx;
					padding: 20rpx;
					border-radius: 20rpx;

					&-title {
						margin-bottom: 20rpx;
						padding: 20rpx 0;
						border-bottom: 1rpx solid #ddd;
						color: #218BCC;
						font-size: 32rpx;
					}

					&-subtitle {
						font-size: 28rpx;
						color: #999;
					}
				}
			}
		}

		.footer {
			position: fixed;
			left: 0;
			bottom: 0;
			right: 0;

			.btn {
				width: 100%;
				height: 120rpx;
				line-height: 120rpx;
				background-color: #D7A768;
				text-align: center;
				color: #fff;
			}
		}
	}
</style>